package com.oneinlet.client

import io.netty.channel.Channel
import java.util.concurrent.ConcurrentHashMap

/**
 * Created by WangZiHe on 2019/1/10
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */
object ClientChannelManage {

    /***
     *  缓存与YCServer建立的通道
     * */
    lateinit var YCServerChannel: Channel
    /***
     *  存储用户端那边请求的通道，我们需要把通过代理请求的数据，再通过该通道原路返回回去
     * **/
    private val clientProxyChannelMap = ConcurrentHashMap<String, Channel>()

    fun addClientProxyChannel(channelId: String, channel: Channel) {
        clientProxyChannelMap[channelId] = channel
    }

    fun removeClientProxyChannel(channelId: String) {
        clientProxyChannelMap.remove(channelId)
    }

    fun getClientProxyChannel(channelId: String): Channel? {
        return clientProxyChannelMap.getOrDefault(channelId, null)
    }

    fun getClientProxyChannelSize(): Int {
        return clientProxyChannelMap.size
    }
}